import { createSlice } from '@reduxjs/toolkit';


const store = createSlice({
    name: 'list',
    initialState: {
        list: [],
    },
    // 同步修改方法
    reducers: {
        setList(state, action) {
            state.list = action.payload;
        },
        deleteById(state, action) {
            const index = state.list.findIndex(it => it.id===action.payload);
            state.list.splice(index, 1);
        }
    },
});

const { setList, deleteById } = store.actions;

export {setList, deleteById};

const listReducer = store.reducer;

export default listReducer;